package forestsimulatorp3.model.simulator;

import model.enums.Season;


/**
 * Represents the time
 * @author dielson
 *
 */
public class Time {

	// Constants ---------------------------------------------------------------

	private static final int INITIAL_CYCLE = 0;
	private static final int SEASON_TIME = 20;
	private static final Season INITIAL_SEASON = Season.SUMMER;

	// Attributes --------------------------------------------------------------

	private static long currentCycle = INITIAL_CYCLE;
	private static Season currentSeason = INITIAL_SEASON;
	private static int timeLeftForNextSeason;

	// Public Methods ----------------------------------------------------------

	/**
	 * Returns the current season of the forest
	 * @return
	 */
	public static Season getCurrentSeason() {
		return currentSeason;
	}

	/**
	 * Returns the current cycle of the forest
	 * @return
	 */
	public static long getCurrentCycle() {
		return currentCycle;
	}

	/**
	 * Advances one cycle on the forest.
	 */
	public static void advanceForestCycle() {

		Time.setCurrentCycle(Time.getCurrentCycle() + 1);

		if (timeLeftForNextSeason == 0) {
			advanceSeason();
		} else {
			timeLeftForNextSeason--;
		}
	}

	// Private Methods ---------------------------------------------------------

	/**
	 * Advances one season in the course of the time
	 */
	private static void advanceSeason() {
		setCurrentSeason(Season.getNext(getCurrentSeason()));
		timeLeftForNextSeason = SEASON_TIME;
	}

	protected static void setCurrentCycle(long actualCycle) {
		Time.currentCycle = actualCycle;
	}

	protected static void setCurrentSeason(Season currentSeason) {
		Time.currentSeason = currentSeason;
	}
}
